//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MarketModelPathwiseMultiProduct.h"
using namespace Cephei::QL::Models::Marketmodels;
#include <gen/QL/Models/Marketmodels/EvolutionDescription.h>
#include <gen/QL/Models/Marketmodels/CurveState.h>
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarketModelPathwiseMultiProduct = NULL;
#endif
	_ppMarketModelPathwiseMultiProduct = &childNative;
    
}
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (QuantLib::MarketModelPathwiseMultiProduct& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMarketModelPathwiseMultiProduct = NULL;
#endif
	_ppMarketModelPathwiseMultiProduct = new boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct> (&childNative);
    
    _MarketModelPathwiseMultiProductOwner = owner;
    
}

Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (CMarketModelPathwiseMultiProduct^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarketModelPathwiseMultiProduct = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMarketModelPathwiseMultiProduct = new boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarketModelPathwiseMultiProduct = NULL;
#endif
	if (!t->IsSubclassOf(CMarketModelPathwiseMultiProduct::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (QuantLib::Handle<QuantLib::MarketModelPathwiseMultiProduct>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMarketModelPathwiseMultiProduct = &childNative;
	_ppMarketModelPathwiseMultiProduct = &static_cast<boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct>>(childNative.currentLink());
    
    _MarketModelPathwiseMultiProductOwner = owner;
}
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (QuantLib::Handle<QuantLib::MarketModelPathwiseMultiProduct> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMarketModelPathwiseMultiProduct = &childNative;
	_ppMarketModelPathwiseMultiProduct = &static_cast<boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::CMarketModelPathwiseMultiProduct (QuantLib::MarketModelPathwiseMultiProduct childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarketModelPathwiseMultiProduct = NULL;
#endif
	_ppMarketModelPathwiseMultiProduct = new boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct> (new QuantLib::MarketModelPathwiseMultiProduct (childNative));
    
}
#endif

Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::~CMarketModelPathwiseMultiProduct ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMarketModelPathwiseMultiProduct != NULL)
    {
	    delete _ppMarketModelPathwiseMultiProduct;
        _ppMarketModelPathwiseMultiProduct = NULL;
    }
}
Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::!CMarketModelPathwiseMultiProduct ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMarketModelPathwiseMultiProduct != NULL)
    {
	    delete _ppMarketModelPathwiseMultiProduct;
    }
}
QuantLib::MarketModelPathwiseMultiProduct& Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::GetReference ()
{
    if (_ppMarketModelPathwiseMultiProduct == NULL) throw gcnew NativeNullException ();
	return **_ppMarketModelPathwiseMultiProduct;
}
boost::shared_ptr<QuantLib::MarketModelPathwiseMultiProduct>& Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::GetShared ()
{
    if (_ppMarketModelPathwiseMultiProduct == NULL) throw gcnew NativeNullException ();
	return *_ppMarketModelPathwiseMultiProduct;
}
QuantLib::MarketModelPathwiseMultiProduct* Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::GetPointer ()
{
    if (_ppMarketModelPathwiseMultiProduct == NULL) throw gcnew NativeNullException ();
	return &**_ppMarketModelPathwiseMultiProduct;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MarketModelPathwiseMultiProduct>& Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::GetHandle ()
{
	if (_phMarketModelPathwiseMultiProduct == NULL)
	{
		_phMarketModelPathwiseMultiProduct = new Handle<QuantLib::MarketModelPathwiseMultiProduct> (*_ppMarketModelPathwiseMultiProduct);
	}
	return *_phMarketModelPathwiseMultiProduct;
}
#endif
bool Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::HasNative () 
{
	return (_ppMarketModelPathwiseMultiProduct != NULL);
}

Boolean Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::AlreadyDeflated::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppMarketModelPathwiseMultiProduct)->alreadyDeflated ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::IEvolutionDescription^ Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::Evolution::get ()
{
    try
    {
    	QuantLib::EvolutionDescription& _rv = (QuantLib::EvolutionDescription&)(*_ppMarketModelPathwiseMultiProduct)->evolution ( );   
        Cephei::QL::Models::Marketmodels::CEvolutionDescription^ _nrv = gcnew Cephei::QL::Models::Marketmodels::CEvolutionDescription (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::MaxNumberOfCashFlowsPerProductPerStep::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppMarketModelPathwiseMultiProduct)->maxNumberOfCashFlowsPerProductPerStep ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::NumberOfProducts::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppMarketModelPathwiseMultiProduct)->numberOfProducts ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::PossibleCashFlowTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time> _rv = (std::vector<QuantLib::Time>)(*_ppMarketModelPathwiseMultiProduct)->possibleCashFlowTimes ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::IMarketModelPathwiseMultiProduct^ Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::Reset::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppMarketModelPathwiseMultiProduct)->reset ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::CMarketModelPathwiseMultiProduct::SuggestedNumeraires::get ()
{
    try
    {
    	std::vector<QuantLib::Size> _rv = (std::vector<QuantLib::Size>)(*_ppMarketModelPathwiseMultiProduct)->suggestedNumeraires ( );   
        Cephei::IVector<UInt64>^ _nrv = gcnew CoVector<UInt64> (gcnew CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

